import urllib2
import urllib
import httplib
import cookielib
import json
import hashlib
import xmpp

resp=urllib2.urlopen('https://login.sina.com.cn/sso/login.php?username=11025&password=c45aff4d5476225a30bc143d5f1d9f59&pwencode=md5&service=sinauc&returntype=TEXT2&client=app')
jsonres=json.loads(resp.read())
tgt=jsonres['ticket']

conn=xmpp.Client('58.63.237.88',debug=[])
conres=conn.connect()
print conres
authres=conn.auth(tgt,"",'python')
#authres=conn.auth('11025','Xicun2xiang','python')
print authres
#print conn.getRoster()

updateurl='http://218.30.115.182/sso/update?tgt='+tgt
print updateurl
req=urllib2.Request(updateurl)
#req.add_header('User-Agent', 'httpclient-vika/1.0')
#req.add_header('Accept', '*/*')
resp=urllib2.urlopen(req)
jsonresp=json.loads(resp.read())
tgt=jsonresp['tgt']
print tgt

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)

#tgt='80c3ef4addb7be199046542019eaa2c6'
req=urllib2.Request('http://disk.sbox.uc.sina.com.cn/webdisk/login.php?username=11025&password='+tgt)
resp=urllib2.urlopen(req)
print resp.read()

req=urllib2.Request('http://disk.sbox.uc.sina.com.cn/webdisk/list.php?dirid=0&accept=json')
resp=urllib2.urlopen(req)
jsonresp=json.loads(resp.read())
files=jsonresp['files']
print files
for file in files:
	print type(file['name'])
	print file['id'],file['name'].encode('utf-8')
#	print file['id'],file['name']
	urllib.urlretrieve('http://fs.sbox.uc.sina.com.cn/sbox_browser_download/?uid=11025&fid='+file['id']+'&shareid=11025&tgt='+tgt, '/sdcard/data/'+file['name'].encode('utf-8'))
#	urllib.urlretrieve('http://fs.sbox.uc.sina.com.cn/sbox_browser_download/?uid=11025&fid='+file['id']+'&shareid=11025&tgt='+tgt, 'f:/pytest/'+file['name']) 